#include <unistd.h>
#include <signal.h>
#include <sys/time.h>
#include "Common/Debug.h"

// Get current system time from system stared, in milliseconds
unsigned long os_GetCurTime(void)
{
	struct timeval tv;
	struct timezone tz;
	unsigned long ts;
	
	gettimeofday(&tv, &tz);
	ts = tv.tv_sec * 1000 + tv.tv_usec / 1000;
	
	return ts;
}

// Suspend the execution of the current thread, in milliseconds
void os_Sleep(int ms)
{
	usleep(ms * 1000);
}

static int _SystemTerm = -1;	// signal handler not installed

static void _SystemTermHandler()
{
	LOG("_SystemTermHandler: signal triggered!\n");

	_SystemTerm = 1;
}

int os_IsSystemTerm()
{
	return _SystemTerm;
}
